var PROFILE = function () {	
    this.TEXTs = [];
    this.DATEs = [];
    this.SELECTs = [];
    this.IMGs = [];    
    this.NUMBERs = [];
    this.PKFIELDs = null; // PK field
    this.REQUIREs = []; // require - not pk field
    this.BUTTONs = [];
    this.FILES = []; // chua thanh phan de upload document
    
    this.fieldsetID = ''; // fieldset chua noi dung cua tung tai san
    this.divAssetID = ''; // the div chua noi dung cua fieldset
    
    // key down textbox
    this.txtKeyDown = function (e) {
        // Allow: backspace, delete, tab, escape, and enter
    	var event = e;
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9
		    || event.keyCode == 27 || event.keyCode == 13 ||
        // Allow: Ctrl+A
		    (event.keyCode == 65 && event.ctrlKey === true) ||
        // Allow: home, end, left, right
		    (event.keyCode >= 35 && event.keyCode <= 39)) {
            // let it happen, don't do anything
            return;
        }
        // Allow: .
        else if (event.keyCode == 190) {
        	var ua = $.browser;
        	var idElement = "";
        	var ua = $.browser;
            if (!ua.mozilla) idElement = event.srcElement.id;
            else idElement = event.target.id;
            var objElement = document.getElementById(idElement);
            var sText = objElement.value;
            var isDecimal = objElement.getAttribute("IsDecimal");
            if ((sText.indexOf('.') == -1) && (isDecimal == 1)
			    && (sText.length > 0))
                return;
            else
                event.preventDefault();
        } else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57)
			    && (event.keyCode < 96 || event.keyCode > 105)) {
                event.preventDefault();
            }
        }
    };
    
    this.invalidForm = function() {
    	for (var i = 0; i < this.REQUIREs.length; i++) {
            var $target = $(this.REQUIREs[i]);
            if(base.trim($target.val()) == '')
        	{
        		var msg = LANGUAGE['gp_required_data'];
        		var required_msg = $target.attr('required_msg');
        		msg = msg.replace("{0}", required_msg);
        		alert(msg);
        		$($target).focus();
            	return false;
        	}
    	}
    	return true;
	};
	
    this.reset = function() {
    	for (var i = 0; i < this.NUMBERs.length; i++) {
            var $target = $(this.NUMBERs[i]);
            $target.val("0");
    	}
    	for (var i = 0; i < this.TEXTs.length; i++) {
            var $target = $(this.TEXTs[i]);
            $target.val("");
    	}
    	for (var i = 0; i < this.DATEs.length; i++) {
            var $target = $(this.DATEs[i]);
            $target.val("");
    	}
    	for (var i = 0; i < this.SELECTs.length; i++) {
            var $target = $(this.SELECTs[i]);
            if($target.length > 0) $target[0].selectedIndex = 0;
    	}
    	$('#' + this.fieldsetID + ' select').uniform();
	};
	
    this.init = function (objProfile) {        
        for (var i = 0; i < this.DATEs.length; i++) {
            var $target = $(this.DATEs[i]);
            $target.datepicker({
                numberOfMonths: 1,
                constrainInput: true,
                dateFormat: 'dd/mm/yy',
                showButtonPanel: false,
                hideIfNoPrevNext: true,
                autoSize: false,
                onSelect: function (dateValue) {
                	// format: dd/mm/yyyy
                    var splitDate = dateValue.split('/');
                    var year = parseInt(splitDate[2]);
                    var month = parseInt(splitDate[1]);
                    var day = parseInt(splitDate[0]);
                    if (month < 10) month = "0" + month;
                    if (day < 10) day = "0" + day;
                    var date = year + "-" + month + "-" + day;
                    var idElement = this.id;
                }
            });
        }

        for (var i = 0; i < this.NUMBERs.length; i++) {
            var $target = $(this.NUMBERs[i]);
            $target.keydown(function (e) {
            	var targetELement = e;
                objProfile.txtKeyDown(targetELement);
            });
        }

    	$('#' + this.fieldsetID + ' select').uniform();
    };
};

var profile_vhtt = new PROFILE();
var profile_thicongCT = new PROFILE();
var profile_xdtramBTS = new PROFILE();
var profile_xdtramBTS_Sync_DTT = new PROFILE();
var profile_ctngamdothi = new PROFILE();
var profile_xdnhao = new PROFILE();
var profile_capphepnhaoriengle = new PROFILE();